//
//  PendApprovallCanleAlertView.m
//  ZJControlsClass
//
//  Created by mac on 2024/11/14.
//

#import "PendApprovallCanleAlertView.h"

@interface PendApprovallCanleAlertView ()

@property (nonatomic,strong) UIView * follewView;
@property (nonatomic,strong) UILabel * titleLabel;
@property (nonatomic,strong) UIButton * dissmissBtn;
@property (nonatomic,strong) UITextView * inputTextV;
@property (nonatomic,strong) UILabel *placeholderLabel;
@property (nonatomic,strong) UIButton * backBtn;
@property (nonatomic,strong) UIButton * TurnDownBtn;


@end



@implementation PendApprovallCanleAlertView


- (instancetype)init
{
    self = [super initWithFrame:[UIApplication sharedApplication].keyWindow.frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
        
       
        [self configUI];
        
    }
    return self;
}

-(void)setTypeStr:(NSString *)typeStr{
    _typeStr = typeStr;
    if ([typeStr isEqualToString:@"确认通过"]){
        self.placeholderLabel.text = @"请输入同意原因";
    }else{
        self.placeholderLabel.text = @"请输入拒绝原因";
    }
    
    [self.TurnDownBtn setTitle:typeStr forState:UIControlStateNormal];
}

-(void)configUI{
    
    [self addSubview:self.follewView];
    [self.follewView addSubview:self.titleLabel];
    [self.follewView addSubview:self.dissmissBtn];
    [self.follewView addSubview:self.inputTextV];
    [self.follewView addSubview:self.backBtn];
    [self.follewView addSubview:self.TurnDownBtn];
    
    
    [self.follewView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.centerY.equalTo(self.mas_centerY);
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(320), ALIGN_HEIGHT_PT(326))));
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.follewView.mas_centerX);
        make.top.equalTo(self.follewView).with.offset(ALIGN_HEIGHT_PT(30));
    }];
    
    [self.dissmissBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.follewView).with.offset(-ALIGN_WIDTH_PT(15));
        make.top.equalTo(self.follewView).with.offset(ALIGN_HEIGHT_PT(15));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(22), ALIGN_WIDTH_PT(22))));
    }];
    

    [self.inputTextV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.follewView).with.offset(ALIGN_WIDTH_PT(15));
        make.right.equalTo(self.follewView).with.offset(-ALIGN_WIDTH_PT(15));
        make.top.equalTo(self.titleLabel.mas_bottom).with.offset(ALIGN_HEIGHT_PT(15));
        make.height.equalTo(@(ALIGN_HEIGHT_PT(164)));
    }];
    
    [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.follewView).with.offset(ALIGN_WIDTH_PT(28));
        make.top.equalTo(self.inputTextV.mas_bottom).with.offset(ALIGN_HEIGHT_PT(20));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(125), ALIGN_HEIGHT_PT(40))));
    }];
    
    [self.TurnDownBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.follewView).with.offset(-ALIGN_WIDTH_PT(28));
        make.top.equalTo(self.inputTextV.mas_bottom).with.offset(ALIGN_HEIGHT_PT(20));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(125), ALIGN_HEIGHT_PT(40))));
    }];
    
    [UIView animateWithDuration:0.25 animations:^{
        [self.follewView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX);
            make.top.equalTo(self.mas_bottom);
            make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(320), ALIGN_HEIGHT_PT(326))));
        }];
        
    }];
    
    
}



#pragma amrk -- 点击事件
-(void)respondsTo_dissmissBtn{
    
    [UIView animateWithDuration:0.25 animations:^{

        [self.follewView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_centerX);
            make.top.equalTo(self.mas_bottom);
            make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(320), ALIGN_HEIGHT_PT(326))));
        }];
        
    } completion:^(BOOL finished) {

        [self removeFromSuperview];
    }];

}

-(void)respondsTo_backBtn{
    [self respondsTo_dissmissBtn];
    
    
    
}
-(void)respondsTo_TurnDownBtn{
    [self respondsTo_dissmissBtn];
    _block(self.inputTextV.text);
    
}



#pragma mark -- 懒加载
-(UIView *)follewView{
    if (!_follewView){
        _follewView = [UIView new];
        _follewView.backgroundColor = [UIColor whiteColor];
        _follewView.layer.cornerRadius = 10;
        _follewView.layer.masksToBounds = YES;
    }
    return _follewView;
}

-(UILabel *)titleLabel{
    if (!_titleLabel){
        _titleLabel = [UILabel new];
        _titleLabel.text = @"审批确认";
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.font = FONT20;
    }
    return _titleLabel;
}

-(UIButton *)dissmissBtn{
    if (!_dissmissBtn){
        _dissmissBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_dissmissBtn setImage:[UIImage imageNamed:@"Frame"] forState:(UIControlStateNormal)];
        [_dissmissBtn addTarget:self action:@selector(respondsTo_dissmissBtn) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _dissmissBtn;
}
-(UITextView *)inputTextV{
    if (!_inputTextV){
        _inputTextV = [[UITextView alloc] init];
        _inputTextV.backgroundColor = COLOR_RGB(242, 242, 242);
        
        _inputTextV.font = FONT14;
        _inputTextV.layer.cornerRadius = 10;
        _inputTextV.layer.masksToBounds = YES;
        _inputTextV.textColor = [UIColor blackColor];

        // 设置placeholder
        self.placeholderLabel = [[UILabel alloc] init];
//        self.placeholderLabel.text = @"请输入审批意见";
        self.placeholderLabel.font = FONT14;
        self.placeholderLabel.textColor = [UIColor grayColor];
        self.placeholderLabel.frame = CGRectMake(5, 8, 200, 20);
        [_inputTextV addSubview:self.placeholderLabel];

        // 监听输入,隐藏placeholder
        [[NSNotificationCenter defaultCenter] addObserverForName:UITextViewTextDidChangeNotification object:_inputTextV queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
            self.placeholderLabel.hidden = self.inputTextV.text.length > 0;
        }];
        
    }
    return _inputTextV;
}




-(UIButton *)backBtn{
    if (!_backBtn){
        _backBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_backBtn setTitle:@"取消" forState:(UIControlStateNormal)];
        _backBtn.layer.cornerRadius = 5;
        _backBtn.layer.masksToBounds = YES;
        _backBtn.layer.borderColor = COLOR_RGB(50, 113, 237).CGColor;
        _backBtn.layer.borderWidth = 1;
        _backBtn.backgroundColor = [UIColor whiteColor];
        [_backBtn setTitleColor:COLOR_RGB(50, 113, 237) forState:(UIControlStateNormal)];
        [_backBtn addTarget:self action:@selector(respondsTo_backBtn) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _backBtn;
}

-(UIButton *)TurnDownBtn{
    if (!_TurnDownBtn){
        _TurnDownBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_TurnDownBtn setTitle:@"确认驳回" forState:(UIControlStateNormal)];
        [_TurnDownBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _TurnDownBtn.layer.cornerRadius = 5;
        _TurnDownBtn.layer.masksToBounds = YES;
        _TurnDownBtn.backgroundColor = COLOR_RGB(50, 113, 237);
        [_TurnDownBtn addTarget:self action:@selector(respondsTo_TurnDownBtn) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _TurnDownBtn;
}











@end
